package com.Tread;


import java.util.concurrent.locks.ReentrantLock;

public class DeadLock {
    static ReentrantLock lock1 = new ReentrantLock();
    static ReentrantLock lock2 = new ReentrantLock();
    public static void main(String[] args) {
        new Thread(new A()).start();
        new Thread(new B()).start();
        System.out.println("sdfs");
    }

}

class A implements Runnable {

    @Override
    public void run() {
        DeadLock.lock2.lock();
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("A get  2");
        DeadLock.lock1.lock();
        System.out.println("A get  1");
        DeadLock.lock2.unlock();
        DeadLock.lock1.unlock();
    }
}

class B implements Runnable {

    @Override
    public void run() {
        DeadLock.lock1.lock();

        System.out.println("B get  1");
        DeadLock.lock2.lock();
        System.out.println("B get  2");
        DeadLock.lock1.unlock();
        DeadLock.lock2.unlock();
    }
}



